const Storage = require('../utils/storage');
const $api = require('../request/api').API;
const app = getApp();
Component({
  data: {
    list: [
      {
        id: 1,
        pagePath: 'pages/home/index',
        text: '首页',
        iconPath: '../static/tabbar/mall.png',
        selectedIconPath: '../static/tabbar/mall-on.png'
      },
      {
        id: 2,
        pagePath: 'pages/equipment/index',
        text: '设备',
        iconPath: '../static/tabbar/equip.png',
        selectedIconPath: '../static/tabbar/equip-on.png'
      },
      {
        id: 3,
        pagePath: 'pages/order/index',
        text: '订单',
        iconPath: '../static/tabbar/list.png',
        selectedIconPath: '../static/tabbar/list-on.png'
      },
      {
        id: 4,
        pagePath: 'pages/message/index',
        text: '消息',
        iconPath: '../static/tabbar/msg.png',
        selectedIconPath: '../static/tabbar/msg-on.png'
      },
      {
        id: 5,
        pagePath: 'pages/person/index',
        text: '我的',
        iconPath: '../static/tabbar/person.png',
        selectedIconPath: '../static/tabbar/person-on.png'
      }
    ],
    currentindex: 0,
    msgCount: 0
  },
  ready() {
    if (wx.getStorageSync(Storage.ACCESS_TOKEN)) {
      $api.checkoutIsReadCount({}).then(res => {
        this.setData({ msgCount: res.data.data });
      });
    }
  },
  methods: {
    switchTab(e) {
      let page = '/' + e.currentTarget.dataset.path;
      wx.switchTab({
        url: page
      });
    }
  }
});
